package com.cms.recursoshumanos.container;

import com.cms.recursoshumanos.component.base.ListStyleButtonField;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
/**
 * 
 */
public class ListStyleButtonSetScrollManager extends VerticalScrollManager {
    public static final int MARGIN = 15;
    public RecursosHumanosScreen screen = null;
    
    public ListStyleButtonSetScrollManager()
    {
        super();
        setMargin( MARGIN, MARGIN, MARGIN, MARGIN );
    }
    
    public int getSelectedIndex() {
    	return this.getFieldWithFocusIndex();
    }
    public void setScreen(RecursosHumanosScreen sc) {
    	this.screen = sc;
    }
    protected void sublayout( int maxWidth, int maxHeight )
    {
        super.sublayout( maxWidth, maxHeight );
        
        int numChildren = this.getFieldCount();
        if( numChildren > 0 ) {
            if( numChildren == 1 ) {
                Field child = getField( 0 );
                if( child instanceof ListStyleButtonField ) {
                    ( (ListStyleButtonField) child ).setDrawPosition( ListStyleButtonField.DRAWPOSITION_SINGLE );
                }
            } else {
                int index = 0;
                Field child = getField( index );
                if( child instanceof ListStyleButtonField ) {
                    ( (ListStyleButtonField) child ).setDrawPosition( ListStyleButtonField.DRAWPOSITION_TOP );
                }
                for( index = 1; index < numChildren - 1 ; index++ ) {
                    child = getField( index );
                    if( child instanceof ListStyleButtonField ) {
                        ( (ListStyleButtonField) child ).setDrawPosition( ListStyleButtonField.DRAWPOSITION_MIDDLE );
                    }
                }
                child = getField( index );
                if( child instanceof ListStyleButtonField ) {
                    ( (ListStyleButtonField) child ).setDrawPosition( ListStyleButtonField.DRAWPOSITION_BOTTOM );
                }
            }
        }
    }
       
    public void scrollChanged(Manager mgr, int newX, int newY) {
    	/*int height = this.getVirtualHeight();
    	int seeHeight = this.getVisibleHeight();
    	
    	if(newY > height-(seeHeight+100) && screen.loading == false) {
    		screen.goMore();
    	}*/
    	super.scrollChanged(mgr, newX, newY);
    }
}